package com.lxy.aimin.ai.config;


import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 *
 * @author 渣哥
 */
@Configuration
@RequiredArgsConstructor
public class ChatClientConfig {

    // 配置模型
    // 会话存储方案


    private final ChatStorageMemory chatMemory;

/*    @Bean
    public ChatClient openAiChatClient(OllamaChatModel chatModel) {

*//*        // 会话存储本机内存方案
        MessageWindowChatMemory chatMemory = MessageWindowChatMemory.builder().build();*//*

        // 会话存储数据库方案
        MessageChatMemoryAdvisor messageChatMemoryAdvisor = MessageChatMemoryAdvisor.builder(chatMemory).build();

        // 创建模型
        return ChatClient.builder(chatModel)
                .defaultAdvisors(
                        messageChatMemoryAdvisor
                )
                .build();
    }*/



    @Bean
    public ChatClient dashScopeChatClient(ChatClient.Builder builder) {
        // 会话存储数据库方案
        MessageChatMemoryAdvisor messageChatMemoryAdvisor = MessageChatMemoryAdvisor.builder(chatMemory).build();
        return builder.defaultAdvisors(messageChatMemoryAdvisor).build();
    }

}
